<template>
  <div class="md:flex">
    <template v-for="(item, index) in growCardList" :key="item.title">
      <Card
        size="small"
        :loading="loading"
        :title="item.title"
        class="md:w-1/4 w-full !md:mt-0 !mt-4"
        :class="[index + 1 < 4 && '!md:mr-3']"
        :canExpan="false"
      >
        <template #extra>
          <Tag :color="item.color">{{ item.action }}</Tag>
        </template>

        <div class="py-4 px-4 flex justify-between">
          <CountTo :prefix="item.prefix" :startVal="1" :endVal="item.value" :decimals="item?.decimals ?? 0" class="text-2xl" />
          <Icon :icon="item.icon" :size="50" />
        </div>

        <div class="p-2 px-4 flex justify-between">
          <!-- <span>总{{ item.title }}</span>
          <CountTo prefix="$" :startVal="1" :endVal="item.total" /> -->
        </div>
      </Card>
    </template>
  </div>
</template>
<script lang="ts" setup>
  import { computed, PropType } from 'vue';
  import { CountTo } from '/@/components/CountTo/index';
  import { Icon } from '/@/components/Icon';
  import { Tag, Card } from 'ant-design-vue';
  import type { growCardDataType } from '../api';
  import { useI18n } from '/@/hooks/web/useI18n';
  const { t } = useI18n('dashboard');

  const props = defineProps({
    overviewData: {
      type: Object as PropType<growCardDataType>,
      required: true,
    },
    loading: {
      type: Boolean,
    },
  });
  Promise.all;
  interface GrowCardItem {
    icon: string;
    title: string;
    value?: number;
    color?: string;
    action?: string;
    decimals?: number;
    footer?: string;
    prefix?: string;
  }

  const growCardList = computed<GrowCardItem[]>(() => [
    {
      title: t('assetTotalCount'),
      icon: 'asset-count|svg',
      value: props.overviewData?.totalCount,
      color: 'blue',
      action: t('amount'),
    },
    {
      title: t('assetTotalPrice'),
      icon: 'total-price|svg',
      value: props.overviewData?.totalPrice,
      color: 'yellow',
      decimals: 2,
      prefix: t('unit'),
      action: t('price'),
    },
    {
      title: t('deviceOnlineCount'),
      icon: 'online|svg',
      value: props.overviewData?.deviceOnline,
      color: 'green',
      action: t('online'),
    },
    {
      title: t('deviceOfflineCount'),
      icon: 'offline|svg',
      value: props.overviewData?.deviceOffline,
      color: 'red',
      action: t('offline'),
    },
  ]);
</script>
